# -*- coding: utf-8 -*-
import scrapy
from scrapytest.items import ItcastItem

class ItcastSpider(scrapy.Spider):
    name = 'itcast'
    allowed_domains = ['itcast.cn']
    start_urls = ['http://www.itcast.cn/channel/teacher.shtml']

    def parse(self, response):
        node_list = response.xpath("//div[@class='li_txt']")
        for node in node_list:
            item = ItcastItem()
            #  此处xpatch必须有.表示从当前div开始
            item['name'] = node.xpath("./h3/text()").extract_first()
            item['title'] = node.xpath("./h4/text()").extract_first()
            item['info'] = node.xpath("./p/text()").extract_first()
            #print("== name=%s, title=%s, info=%s =="%(item['name'], item['title'], item['info']))

            # 返回给引擎
            yield item

     #   return scrapy.Request(url) 返回给调度器
